Framework EDI Reference. Methods and Properties
ediSecurities. ImportCertificatePfx

Imports certificate(s) and its associated private key from a PFX file.

Syntax:

Parameters:

Returns:

Returns an object of type FREDI.ediSecurityCertificate if imported successfully; otherwise NULL or an empty object is returned if the operation fails.  For PFX files containing multiple certificates, the object returned is the object of the last certificate successfully imported.

Remarks:

The PFX file may contain multiple certificates with their associated private keys (Note. A certificate does not have to have an associated private key).  Each certificate will be imported and stored into the default certificate store, and a new key container with a unique GUID name is created in the CSP database for each associated private key.  If an error is generated while importing multiple certificates, all certificates already imported successfully until the time the error was generated will remain in the certificate store -- that is, the error does not revert the operation back.

The sServiceProvider and lProviderType specify the database where the private key container will be stored.  If sServiceProvider and/or lProviderType are not specified, the default CSP database is used, which is specified by DefaultProviderName andServiceProviderType.  The type of database, whether machine key set or user key set, is specified using ediDocument.Option by the constant OptDocument_MachineKeySet.

The default certificate store is specified by the properties DefaultCertSystemStoreName and DefaultCertSystemStoreLocation.

Example:

Dim oEdiDoc As Fredi.ediDocument
Dim oSecurities As Fredi.ediSecurities
Dim oCertificate As Fredi.ediSecurityCertificate

' Create instance of Framework EDI.
Set oEdiDoc = New Fredi.ediDocument

' Get securities object.
Set oSecurities = oEdiDoc.GetSecurities

' Set the default certificate store
oSecurities.DefaultCertSystemStoreName = "My" ' Case sensitive

' Set the default certificate store location
oSecurities.DefaultCertSystemStoreLocation = "CurrentUser"

' Import PFX file.
' Password of PFX file is PASS123.
Set oCertificate = oSecurities.ImportCertificatePfx(App.Path & "\MyExportedTestCert.PFX", "PASS123")
If Not oCertificate Is Nothing Then
MsgBox "Successfully imported PFX file MyExportedTestCert.PFX."

' Get the name of the key container that was created to store the import private key.
If Len(oCertificate.CspKeyContainer) > 0 Then
MsgBox "Key container of Private Key is " & oCertificate.CspKeyContainer

End If
Else
MsgBox "Failed to create certificate"

End If

Sample

M_ImportCertificatePfx.zip